/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.accessorgen;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.core.data.ChildEntityAccessor;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.ReadOnlyAcceptChangeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.ParentIdPropGenerator;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import java.util.ArrayList;

public class ReadOnlyAcsChildGenerator extends ReadOnlyEntityAcsGenerator
{
	private MediateType parentInterfaceType;
	private AccessorClassGenContext rootContext;
	IGspCommonObject childObject;
	public ReadOnlyAcsChildGenerator(EntityGeneratorContext parContext, AccessorClassGenContext rootContext
			, String nodeCode, IGspCommonObject childObject, MediateType targetInterfaceType, MediateType parentInterfaceType)
	{
		super(parContext, childObject, targetInterfaceType);
		this.childObject = childObject;
		this.parentInterfaceType = parentInterfaceType;
		this.rootContext = rootContext;
	}

	@Override
	public AccessorClassGenContext getRootContext(){return rootContext;}
	@Override
	protected ClassMethodGenerator get_AcceptChange_Generator()
	{
		return new ReadOnlyAcceptChangeGen();
	}

	@Override
	protected TypeInfo setParentClass() {
		return new TypeInfo(ChildEntityAccessor.class.getTypeName());
	}

	@Override
	protected void afterGenerate()
	{
		super.afterGenerate();
		rootContext.getAllTypeInfo().getChildAccessorTypes().put(NodeCode, new MediateType("",getName()));
		//Context.AllTypeInfo.ChildObjAccessorCollectionTypes[objectCode] = collectionGenerator.Context.Type;
	}

	@Override
	protected java.util.ArrayList<BaseGenerator> createClassExtendChildGenrators()
	{
		ArrayList<BaseGenerator> gens = super.createClassExtendChildGenrators();
		if (gens == null) {
			gens = new java.util.ArrayList<BaseGenerator>();
		}
		if (ParentIdPropGenerator.NeedGenerate(childObject)) {
			gens.add(new ParentIdPropGenerator(TargetInterfaceType, childObject.findElement(childObject.getKeys().get(0).getSourceElement()).getLabelID()));
		}
		return gens;
	}

}
